package com.sitia.jd.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sitia.common.annotation.Log;
import com.sitia.common.core.controller.BaseController;
import com.sitia.common.core.domain.AjaxResult;
import com.sitia.common.enums.BusinessType;
import com.sitia.jd.domain.MxFile;
import com.sitia.jd.service.IMxFileService;
import com.sitia.common.utils.poi.ExcelUtil;
import com.sitia.common.core.page.TableDataInfo;

/**
 * 文件附件Controller
 * 
 * @author sitia
 * @date 2024-03-15
 */
@RestController
@RequestMapping("/jd/file")
public class MxFileController extends BaseController
{
    @Autowired
    private IMxFileService mxFileService;

    /**
     * 查询文件附件列表
     */
    @PreAuthorize("@ss.hasPermi('jd:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(MxFile mxFile)
    {
        startPage();
        List<MxFile> list = mxFileService.selectMxFileList(mxFile);
        return getDataTable(list);
    }

    /**
     * 导出文件附件列表
     */
    @PreAuthorize("@ss.hasPermi('jd:file:export')")
    @Log(title = "文件附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MxFile mxFile)
    {
        List<MxFile> list = mxFileService.selectMxFileList(mxFile);
        ExcelUtil<MxFile> util = new ExcelUtil<MxFile>(MxFile.class);
        util.exportExcel(response, list, "文件附件数据");
    }

    /**
     * 获取文件附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('jd:file:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(mxFileService.selectMxFileById(id));
    }

    /**
     * 新增文件附件
     */
    @PreAuthorize("@ss.hasPermi('jd:file:add')")
    @Log(title = "文件附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MxFile mxFile)
    {
        return toAjax(mxFileService.insertMxFile(mxFile));
    }

    /**
     * 修改文件附件
     */
    @PreAuthorize("@ss.hasPermi('jd:file:edit')")
    @Log(title = "文件附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MxFile mxFile)
    {
        return toAjax(mxFileService.updateMxFile(mxFile));
    }

    /**
     * 删除文件附件
     */
    @PreAuthorize("@ss.hasPermi('jd:file:remove')")
    @Log(title = "文件附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(mxFileService.deleteMxFileByIds(ids));
    }
}
